from selenium import webdriver
import time

# Chrome浏览器，登录密码为1，恢复出厂保留网络配置
#协议同意
driver = webdriver.Chrome()
driver.get('http://192.168.3.1/html/index.html#/welcome')
while True:
    x = 1
    try:
        driver.find_element_by_id("guide_user_agree_ctrl_checkbox_ctrl")
        x = 2
    except:
        x = 1
    if x == 2:
        break
lable1 = driver.find_element_by_id("guide_user_agree_ctrl_checkbox_ctrl")
lable1.click()
while True:
    x = 1
    try:
        driver.find_element_by_xpath("//div[@class='ui-btn guide_btn_active']")
        x = 2
    except:
        x = 1
    if x == 2:
        time.sleep(0.3)
        break
begin = driver.find_element_by_xpath(
	"//div[@id='guidebtnbegin']/span")
begin.click()
#设备连线
while True:
    x = 1
    try:
        driver.find_element_by_xpath(
	"//div[@class='ui-content textleft']/div[2]/div[2]/span")
        x = 2
    except:
        x = 1
    if x == 2:
        break
lable2 = driver.find_element_by_xpath(
	"//div[@class='ui-content textleft']/div[2]/div[2]/span")
lable2.click()
while True:
    x = 1
    try:
        driver.find_element_by_xpath(
	"//div[@class='ui-btn guide_btn_active']")
        x = 2
    except:
        x = 1
    if x == 2:
        time.sleep(0.3)
        break
scenarionext = driver.find_element_by_xpath("//div[@id='scenarionext']/span")
scenarionext.click()

#网络配置
while True:
    x = 1
    try:
        driver.find_element_by_xpath(
	"//div[@id='wanconfignextbtn']/span")
        x = 2
    except:
        x = 1
    if x == 2:
        time.sleep(0.3)
        break
wanconfignextbtn = driver.find_element_by_xpath(
	"//div[@id='wanconfignextbtn']/span")
wanconfignextbtn.click()

#路由配置
while True:
    x = 1
    try:
        driver.find_element_by_id('guide_wifi_password_ctrl')
        x = 2
    except:
        x = 1
    if x == 2:
        time.sleep(1)
        break
wifi = driver.find_element_by_id('guide_wifi_password_ctrl')
wifi.clear()
wifi.send_keys('12345678')
upd = driver.find_element_by_id('guide_user_pwd_ctrl')
upd.clear()
upd.send_keys('1')
time.sleep(0.3)
guide_wifi_next_btn = driver.find_element_by_xpath(
	"//div[@id='guide_wifi_next_btn']/span")
guide_wifi_next_btn.click()
#安装完成
while True:
    x = 1
    try:
        driver.find_element_by_xpath(
	"//div[@id='wlannext']/span")
        x = 2
    except:
        x = 1
    if x == 2:
        time.sleep(0.3)
        break
wlannext = driver.find_element_by_xpath(
	"//div[@id='wlannext']/span")
wlannext.click()

#完成
while True:
    x = 1
    try:
        driver.find_element_by_xpath(
	"//div[@class='ui-btn guide_btn_active']/span")
        x = 2
    except:
        x = 1
    if x == 2:
        time.sleep(1)
        break
finish = driver.find_element_by_xpath(
	"//div[@class='ui-btn guide_btn_active']/span")
finish.click()
